package com.shihan._01_multi_thread_basic.producer_consumer;

/**
 * @Description 生产者、消费者的主测试类
 * @Author shihan
 * @Date 2021/8/10 7:52
 * @Version 1.0
 */
public class MainTest {

    public static void main(String[] args) {
        //oneProOneCons();
        twoProFourCons();
    }

    /**
     * 一个生产者、一个消费者的场景
     * 预期结果：生产者快消费者一倍，生产者会先阻塞
     */
    public static void oneProOneCons() {
        MyQueue myQueue = new MyQueue();
        Thread proThreadA = new Thread(new MyProducer(myQueue), "生产者A");
        Thread conThreadA = new Thread(new MyConsumer(myQueue), "消费者A");
        proThreadA.start();
        conThreadA.start();
    }

    /**
     * 两个生产者、五个消费者的场景
     * 预期结果：消费者更快，消费者会先阻塞
     */
    public static void twoProFourCons() {
        MyQueue myQueue = new MyQueue();
        Thread proThreadA = new Thread(new MyProducer(myQueue), "生产者A");
        Thread proThreadB = new Thread(new MyProducer(myQueue), "生产者B");
        Thread conThreadA = new Thread(new MyConsumer(myQueue), "消费者A");
        Thread conThreadB = new Thread(new MyConsumer(myQueue), "消费者B");
        Thread conThreadC = new Thread(new MyConsumer(myQueue), "消费者C");
        Thread conThreadD = new Thread(new MyConsumer(myQueue), "消费者D");
        Thread conThreadE = new Thread(new MyConsumer(myQueue), "消费者E");
        proThreadA.start();
        proThreadB.start();
        conThreadA.start();
        conThreadB.start();
        conThreadC.start();
        conThreadD.start();
        conThreadE.start();
    }

}
